package utility;

public class vec2 {

	private float x, y;

	public vec2() {
		x = 0.0f;
		y = 0.0f;
	}

	public vec2(float _x, float _y) {
		x = _x;
		y = _y;
	}

	// math funtions
	public void add(vec2 other) {
		this.x += other.x;
		this.y += other.y;
	}

	public float distance(vec2 other) {
		float dx = other.x - this.x;
		float dy = other.y - this.y;
		return (float) Math.sqrt(dx * dx + dy * dy);
	}

	public float distanceSq(vec2 other) {
		float dx = other.x - this.x;
		float dy = other.y - this.y;
		return (float) (dx * dx + dy * dy);
	}

	public void scale(float scale) {
		this.x *= scale;
		this.y *= scale;
	}

	public void divide(float f) {
		if (f == 0.0f)
			return; // WHYYYYYYY

		this.x /= f;
		this.y /= f;
	}

	public void rotateVector(float rad) {
		this.x = (float) ((float) (x * Math.cos(rad)) - (y * Math.sin(rad)));
		this.y = (float) ((float) (x * Math.sin(rad)) + (y * Math.cos(rad)));
	}
	
	public void Zero()
	{
		x = 0.0f;
		y = 0.0f;
	}

	public float length() {
		return (float) (Math.sqrt((x * x) + (y * y)));
	}

	public float lengthSq() {
		return ((x * x) + (y * y));
	}

	public vec2 normalize() {
		return (new vec2((this.x / this.length()), (this.y / this.length())));
	}

	// accessors
	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	// mutators
	public void setX(float _x) {
		this.x = _x;
	}

	public void setY(float _y) {
		this.y = _y;
	}
}